﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using Domain.Entity;
using Domain.Entity.bs;
using Domain.Entity.sys;
using Domain.Entity.zct;
using Domain.IRepository;

namespace Application.WarehouseService
{
    public class WarehouseService : IWarehouseService
    {
        private readonly IWarehouseRepository warehouseRepository;
        private readonly IMapper mapper;
        public WarehouseService(IWarehouseRepository warehouseRepository, IMapper mapper)
        {
            this.warehouseRepository = warehouseRepository;
            this.mapper = mapper;
        }
        //删除仓库信息
        public async Task<int> DeleteWarehouse(int id)
        {
            return await warehouseRepository.DeleteWarehouse(id);
        }

        //分页查询业务类型信息

        public async Task<FenYe<Warehouse>> GetWarehouse(FenYe<Warehouse> fenYe, int? status, string? whname, string? whdepname, string? whusername)
        {
            return await warehouseRepository.GetWarehouse(fenYe, status, whname, whdepname, whusername);
        }


        //自动获取联系电话
        public async Task<string> GetPhoneByUserName(string userName)
        {
            return await warehouseRepository.GetPhoneByUserName(userName);
        }

        //添加仓库信息
        public async Task<int> AddWarehouse(AddWarehouseDto addWarehouseDto)
        {
            //转换
            Warehouse warehouse = mapper.Map<Warehouse>(addWarehouseDto);
            return await warehouseRepository.AddWarehouse(warehouse);
        }


        //查询仓库主管信息
        public async Task<List<User>> GetAllUsers()
        {
            return await warehouseRepository.GetAllUsers();
        }

        //查询仓库名
        public async Task<List<Warehouse>> GetWarehouses()
        {
            return await warehouseRepository.GetWarehouses();
        }

        //根据id查询仓库信息
        public async Task<Warehouse> GetIdWarehouse(int id)
        {
            return await warehouseRepository.GetIdWarehouse(id);
        }

        //修改仓库信息
        public async Task<int> UpdateWarehouse(UpdateWarehouseDto updateWarehousedto)
        {
            Warehouse warehouse = mapper.Map<Warehouse>(updateWarehousedto);
            return await warehouseRepository.UpdateWarehouse(warehouse);
        }


        //分页高级查询

        public async Task<FenYe<Warehouse>> GetvancedWarehouse(FenYe<Warehouse> fenYe, string? code, string? userName, string? name, string? minCapacity, string? maxCapacity, int? status, string? minNum, string? maxNum, string? depName, string? time)
        {
            return await warehouseRepository.GetvancedWarehouse(fenYe, code, userName, name, minCapacity, maxCapacity, status, minNum, maxNum, depName, time);
        }

        //修改仓库状态
        public async Task<int> UpdateStatus(int id, int wh_status)
        {
            return await warehouseRepository.UpdateStatus(id, wh_status);
        }


        //锁定/解锁仓库
        public async Task<int> LockWarehouse(int whid, int islock)
        {
            return await warehouseRepository.LockWarehouse(whid, islock);
        }
    }
}
